//
//  XBTitleButton.m
//  微博
//
//  Created by Clement_Gu on 16/4/20.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "XBTitleButton.h"
#import "UIImage+Image.h"
#import "UIView+Frame.h"
@implementation XBTitleButton
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //拉伸图片
        [self setBackgroundImage:[UIImage imageWithStretchableName:@"navigationbar_friendsearch_highlighted"]forState:UIControlStateHighlighted];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    if (self.currentImage == nil) {
        return;
    }
    //title
    self.titleLabel.x = self.imageView.x;
    //image
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);

}
//重写setTitle方法 扩展计算尺寸功能
-(void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    
    [self sizeToFit];
}

-(void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    
    [self sizeToFit];

}


@end
